package com.camerareader.mvp.two_d_page;

import android.app.Activity;
import android.content.Intent;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.model.GlideUrl;
import com.bumptech.glide.load.resource.drawable.GlideDrawable;
import com.camerareader.R;
import com.camerareader.common.LoadingBitmapListener;
import com.camerareader.mvp.BaseActivity;
import com.camerareader.mvp.two_d_page.extra.SquareImageView;
import com.fileoperation.user.UserInfo;
import com.nettools.Constants;
import com.nettools.NetTools;

import java.io.InputStream;

public class TwoDActivity extends BaseActivity {

    private ImageView back;
    private SquareImageView twoD;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_two_d);
        initView();
    }

    @Override
    protected void onServiceConnected() {

    }

    @Override
    protected void onServiceDisconnected() {

    }

    private void initView() {
        getWindow().getDecorView().setBackgroundColor(ContextCompat.getColor(this, R.color.colorPrimary));
        back = (ImageView) findViewById(R.id.back);
        twoD = (SquareImageView) findViewById(R.id.two_d);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });

        loadImage();

    }

    private void loadImage() {
        Log.w("url....", NetTools.getTwodUrl());
        Glide.with(this)
                .load(NetTools.getTwodUrl())
                .placeholder(ContextCompat.getDrawable(this, R.drawable.image_placeholder))
                .listener(new LoadingBitmapListener<String, GlideDrawable>())
                .into(twoD);
    }


    @Override
    public void onBackPressed() {
        super.onBackPressed();
        finish();
    }

    public static void navigateTwoDActivity(Activity activity){
        Intent intent = new Intent(activity, TwoDActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        activity.startActivity(intent);
    }
}
